﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.ScheduledTasks.Serialization
{
    public static class SerializationFormatSetup
    {
        /// <summary>
        /// json格式序列化规则
        /// </summary>
        /// <param name="services"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddSerializationFormatSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.AddControllers(ops =>
            {

            }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddNewtonsoftJson(options =>//安装包 Microsoft.AspNetCore.Mvc.NewtonsoftJson
            {
                //设置时间格式
                //options.SerializerSettings.DateFormatString = "yyyy'-'MM'-'dd' 'HH':'mm':'ss.ffffff";
                //设置long类型转换成string类型
                options.SerializerSettings.ContractResolver = new CustomContractResolver();
            });
        }
    }
}
